package com.jz.community.moduleshopping.orderList.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.jz.community.basecomm.base.BaseMvpFragment;
import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.R2;
import com.jz.community.moduleshopping.orderList.adapter.CommonViewPagerAdapter;

import butterknife.BindView;


@Route(path = RouterIntentConstant.MODULE_SHOPPING_ORDER)
public class OrderFragment extends BaseMvpFragment {

    @BindView(R2.id.order_home_title)
    TextView orderHomeTitle;
    @BindView(R2.id.order_home_toolbar)
    Toolbar orderHomeToolbar;
    @BindView(R2.id.order_home_tab)
    SlidingTabLayout orderHomeTab;
    @BindView(R2.id.order_home_viewpager)
    ViewPager orderHomeViewpager;
    private String[] titles = {"全部订单", "待付款", "待发货", "待收货", "待评价"};
    private OrderListFragment orderListFragment;
    private boolean isRefreshOrderData = false;

    public boolean isRefreshOrderData() {
        return isRefreshOrderData;
    }

    public void refreshOrder(boolean refreshOrderData) {
        isRefreshOrderData = refreshOrderData;
        initViewPager();
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.module_shopping_fragment_order_home;
    }

    @Override
    protected void initView() {
        SHelper.vis(orderHomeTab);
        orderHomeTitle.setText("订单列表");
    }

    @Override
    protected void initVisible() {
        setImmersionBar(orderHomeToolbar);
    }

    @Override
    protected void initLazy(@Nullable Bundle savedInstanceState) {
        isRefreshOrderData = true;
        initViewPager();
    }

    private void initViewPager() {
        CommonViewPagerAdapter viewPagerAdapter = new CommonViewPagerAdapter(getChildFragmentManager());
        for (int i = 0; i < titles.length; i++) {
            orderListFragment = OrderListFragment.newInstance(i);
            viewPagerAdapter.addFragment(orderListFragment, i);
        }
        orderHomeViewpager.setOffscreenPageLimit(5);
        orderHomeViewpager.setAdapter(viewPagerAdapter);
        orderHomeTab.setViewPager(orderHomeViewpager, titles);
    }

    @Override
    protected BaseMvpPresenter createPresenter() {
        return null;
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
